<?php
if (!defined('PATH'))
	exit();

$guildLeaderChar = $guild->getOwner();
$rankList = $guild->getGuildRanksList();
$rankList->orderBy('level', POT::ORDER_DESC);

$guildLogo = $guild->getId().'.'.$this->config['website']['guild']['ext'];
if (empty($guildLogo) || !file_exists('media/images/guild_logo/' . $guildLogo))
	$guildLogo = "default_logo.gif";
$guildOwner = $guild->getOwner();
if ($guildOwner->isLoaded())
	$guildOwner = $guildOwner->getName();
$description = $guild->getCustomField('description');
$newlines = array("\r\n", "\n", "\r");
$description_with_lines = str_replace($newlines, '<br />', $description, $count);
if ($count < $this->config['website']['guild']['descriptionLinesLimit'])
	$description = $description_with_lines;
?>
<table border="0" cellpadding="8" cellspacing="1" width="100%">
	<tr class="head"><td width="64px"><img src="<?= PATH ?>/media/images/guild_logo/<?= $guildLogo ?>"/></td><td align="center"><h1><?= $guild->getName() ?></h1></td><td width="64px"><img src="<?= PATH ?>/media/images/guild_logo/<?= $guildLogo ?>"/></td></tr>
	<tr><td colspan="3"><?= $description ?></td></tr>
	<tr><td colspan="3"><a href="<?= PATH ?>/search/check/<?= urlencode($guildOwner) ?>/"><b><?= $guildOwner ?></b></a> is guild leader of <b><?= $guild->getName() ?></b>.<br/>The guild was founded on <?= $this->config['server']['name'] ?> on <?= date($this->config['website']['date_format'], $guild->getCreationData()) ?></td></tr>
</table>
<br/>
<table border="0" cellpadding="8" cellspacing="1" width="100%">
	<tr class="head"><td colspan="2"><b>Guild members</b></td></tr>
	<tr class="bold"><td width="35%">Rank</td><td>Name (nick)</td></tr>
<?php
$nick =  null;
$show_submit = false;
foreach ($rankList as $rank) {
	$playersWithRank = $rank->getPlayersList();
	$playersWithRank->orderBy('name');
	$playersWithRankNumber = count($playersWithRank);
	if ($playersWithRankNumber > 0) {
		$i = 1;
		foreach ($playersWithRank as $player) {
			if (LOGGED && ((in_array($player->getAccount(), $roles['playersFromAccountInGuild']) && !$player->isOnline()) || $roles['access']['leader']))  {
				$show_submit = true;
				$nick = ' <form action="'.PATH.'/guilds/management/'.$guild->getId().'/change_nick/" method="POST"><input type="hidden" name="player" value="'.$player->getId().'"/><input type="text" name="nick" value="'.$player->getGuildNick().'"/><input type="submit" name="save_changes" value="Save"/></form>';
			} else {
				$nick = $player->getGuildNick();
				if (!empty($nick))
					$nick = ' ('.$player->getGuildNick().')';
			}
?>
	<tr><?=($i==1)?'<td valign="top" rowspan="'.$playersWithRankNumber.'" width="35%">'.$rank->getName().'</td>':''?><td><a href="<?=PATH?>/search/check/<?=urlencode($player->getName())?>"><?=$player->getName()?></a><?=$nick?></td></tr>
<?php
			$i++;
		}
	}
}
?>
</table>
<?php
$logged = $this->archez->getLogged();
new InvitesDriver($guild);
$invitedList = $guild->listInvites();
if(count($invitedList) > 0) {
?>
<br/>
<table border="0" cellpadding="8" cellspacing="1" width="100%">
	<tr class="head"><td><b>Invited characters</b></td></tr>
	<tr class="bold"><td>Nick</td></tr>
<?php
	foreach($invitedList as $invitedPlayer)
	{
		$form = null;
		if ($logged == $invitedPlayer->getAccount()) {
			$form = ' <form action="'.PATH.'/guilds/management/'.$guild->getId().'/accept_invite" method="post" style="display:inline;"><input type="hidden" name="player" value="'.$invitedPlayer->getId().'"/><input type="submit" name="submit" value="Accept"/></form> <form action="'.PATH.'/guilds/management/'.$guild->getId().'/cancel_invite" method="post" style="display:inline;"><input type="hidden" name="player" value="'.$invitedPlayer->getId().'"/><input type="submit" name="submit" value="Cancel"/></form>';
		}
?>
	<tr><td><a href="<?=PATH?>/search/check/<?=urlencode($invitedPlayer->getName())?>/"><?=$invitedPlayer->getName()?></a><?=$form?></td></tr>
<?php
	}
?>
</table>
<?php
}
?>

